var mapIds = [993173400];
var 准备地图 = 993173500;

function init() {}

function setup(c, a) {
    em.setProperty("state", 1);
    em.setProperty("leader", "true");
    var c = em.newInstance("荣耀活动_扫荡黑太阳_解救居民");
    for (var b = 0; b < mapIds.length; b++) {
        var d = c.setInstanceMap(mapIds[b]);
        d.resetFully()
    }
    c.setProperty("save", 0);
    c.schedule("开始救援", 90 * 1000);
    c.schedule("居民出现", 1 * 1000);
    c.schedule("怪物出现", c.rand(5, 20) * 1000);
    return c
}
var npcs = [
    [80, -267],
    [-196, -267],
    [842, 35],
    [-1027, -450],
    [-685, -357],
    [-528, -177],
    [1012, -90],
    [1037, -450],
    [-686, -177],
    [-782, 35],
    [480, 35],
    [-1081, -270],
    [418, -357],
    [-201, -431],
    [64, -431],
    [420, -177],
    [-1084, -90],
    [-1047, 35],
    [544, -177]
];
var portals = [
    [805, -92],
    [330, 30],
    [-620, -360],
    [-1120, -92],
    [-55, -435],
    [815, -452],
    [440, -360]
];

function 居民出现(a) {
    a.schedule("居民出现", a.rand(10, 25) * 1000);
    var c = a.getMapInstance(0);
    if (c.getAllReactors().size() > 5) {
        return
    }
    var b = 0;
    a.getPlayers().forEach(function (e) {
        if (b++ == 0) {
            var d = npcs[a.rand(0, npcs.length - 1)];
            e.getAPI().spawnReactorOnGroundBelow(a.rand(9939046, 9939049), d[0], d[1])
        }
        e.getAPI().addPopupSay(9062209, 1000, "塞尔提乌广场残骸中出现了居民！速速保护他们吧！", "", 1)
    })
}

function 传送门出现(a) {
    var c = a.getMapInstance(0);
    if (c.getReactorById(9939050) != null) {
        return
    }
    var b = 0;
    a.getPlayers().forEach(function (e) {
        if (b++ == 0) {
            var d = portals[a.rand(0, portals.length - 1)];
            e.getAPI().spawnReactorOnGroundBelow(9939050, d[0], d[1])
        }
    })
}

function 怪物出现(a) {
    var b = a.getMapInstance(0);
    b.spawnMonsterOnGroundBelow(em.getMonster(9833661), new java.awt.Point(a.rand(b.getLeft(), b.getRight()), a.rand(b.getTop(), b.getBottom() - 200)));
    a.schedule("怪物出现", a.rand(10, 30) * 1000)
}

function 开始等待(a) {
    a.setProperty("save", 0);
    var b = a.getMapInstance(0);
    if (b.getReactorById(9939050) != null) {
        b.getReactorById(9939050).forceTrigger();
        b.getReactorById(9939050).delayedDestroyReactor(2000)
    }
    a.getPlayers().forEach(function (c) {
        c.getAPI().cerniumSaveResidentStart(false);
        c.getAPI().getWeatherEffectNotice("在下一个传送口激活之前，请削减黑太阳士兵的数量！", 297, 10000, 1);
        c.getAPI().playerMessage(5, "请一边消灭黑太阳士兵，一边等待传送口激活。")
    });
    a.schedule("开始救援", 90 * 1000)
}

function 开始救援(a) {
    a.setProperty("save", 1);
    a.getPlayers().forEach(function (b) {
        b.getAPI().cerniumSaveResidentStart(true);
        b.getAPI().getWeatherEffectNotice("传送口激活了！赶快把居民们送去避难！", 297, 10000, 1);
        b.getAPI().playerMessage(5, "请通过传送口帮助救出的居民们逃脱。")
    });
    a.schedule("传送门出现", 1 * 1000);
    a.schedule("开始等待", 60 * 1000)
}

function onPlayerRegistered(b, a) {
    a.setReviveCount(-100);
    var c = b.getMapInstance(0);
    a.changeMap(c, c.getPortal(0))
}

function onPlayerRevived(b, a) {
    return false
}

function onMapChanged(c, b, a) {
    em.setProperty("kill", "0");
    em.setProperty("level", "0");
    em.setProperty("clear", "0");
    em.setProperty("curMap", a);
    if (mapIds.indexOf(a) < 0) {
        on玩家退场(c, b, false);
        return
    }
}

function onPlayerDisconnected(b, a) {
    on玩家退场(b, a, false);
    return 0
}

function onMonsterDamaged(b, a, d, e, c) {}

function onTimeOut(a) {
    a.getPlayers().forEach(function (b) {
        on玩家退场(a, b, true)
    })
}

function onMonsterKilled(b, d, c) {
    var a = em.getNumberProperty("kill") + 1;
    em.setProperty("kill", a)
}

function onPartyDisbanded(a) {}

function onPlayerKilled(b, a) {}
var setupTask;

function randomNum(b, a) {
    switch (arguments.length) {
        case 1:
            return parseInt(Math.random() * b + 1, 10);
            break;
        case 2:
            return parseInt(Math.random() * (a - b + 1) + b, 10);
            break;
        default:
            return 0;
            break
    }
}

function initProp(a, b) {
    if (em.getProperty(a) == null) {
        em.setProperty(a, b)
    }
}

function initPropArray(a, d, c, e) {
    for (var b = c; b <= e; b++) {
        if (em.getProperty(a + "_" + b) == null) {
            em.setProperty(a + "_" + b, d)
        }
    }
}

function on玩家退场(c, b, a) {
    c.disposeIfPlayerBelow(a ? 999 : 0, 准备地图);
    em.getProperties().clear();
    em.setProperty("state", 0);
    em.setProperty("leader", "true");
    c.unregisterPlayer(b)
}

function onItemPickedUp(b, a, c) {};